//
//  DASameReaderView.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/25.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DASameReaderView.h"
#import "UIImageView+WebCache.h"
#import "Utility.h"
#import "DAHeader.h"
#import "UIViewAdditions.h"
@interface DASameReaderView ()
{
    NSInteger userNumber;
    NSArray *dataArray;
//    UIImageView *userImage;
}
@end
@implementation DASameReaderView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
     
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (void)creatReaderUserImageWithArray:(NSArray *)array{
   // userNumber = array.count;
    dataArray = array;
    if (array.count >= 6) {
        userNumber = 6;
    }else{
        userNumber = array.count;
    }
    [self removeAllSubviews];
    for (int i = 0 ; i < userNumber; i++) {
        UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake((30 + 10) * i, 0, 30, 30)];
        userImage.layer.shouldRasterize = YES;
        userImage.layer.rasterizationScale = 5;
        userImage.layer.cornerRadius = 5;
        userImage.clipsToBounds = YES;
        userImage.tag = 4000 + i;
        [self addSubview:userImage];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSameReader:)];
        userImage.userInteractionEnabled = YES;
        [userImage addGestureRecognizer:tap];
        
        [userImage sd_setImageWithURL:[NSURL URLWithString:[[dataArray objectAtIndex:i] objectForKey:@"userFace"] ] placeholderImage:[UIImage imageNamed:@"holderface"] ];
    }
    NSString *first = NSLocalizedString(@"NoOneReaderDoYouWantToBeTheFirstReader", nil);
    
    if (dataArray.count == 0) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 240, 30)];
        label.numberOfLines = 0;
        label.text = first;
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [UIColor colorWithHexString:bookNameColor];
        [self addSubview:label];
    }
}

- (void)clickSameReader:(UITapGestureRecognizer *)tap{
    NSInteger index = tap.view.tag - 4000;
    [self.delegate sameReaderView:index];
    NSLog(@"%ld", index);
    
    
}




- (void)drawRect:(CGRect)rect{
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
